<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        input {
            margin: 10px 5px;
        }
        
        button {
            margin: 10px 5px;
            width: 60px;
        }
    </style>
</head>

<body>
    <form >
        你爱好的运动是？<input type="checkbox">全选/全不选<br>
        <input type="checkbox" name="item" value="足球">足球
        <input id="basketball" type="checkbox" name="item" value="篮球">篮球
        <input type="checkbox" name="item" value="羽毛球">羽毛球
        <input type="checkbox" name="item" value="乒乓球">乒乓球<br>
        <button type='submit'  id="checkboxAllbut">全选</button>
        <button type='button'  id="checkboxNotAllbut">全不选</button>
        <button type='button'  id="checkboxfan">反转</button>
        <button type='button'  id="checkboxsubmit">提交</button>
    </form>

    <script>
        let checkboxAllbut = document.getElementById("checkboxAllbut");
        // 先获取四个球类对象
        let items = document.getElementsByName("item");

        // 全选按钮 点击按钮四个多选框全部被选中
        checkboxAllbut.onclick = function(e) {
            e.preventDefault();
            
            // 设置四个多选框全部被选中
            for (var i = 0; i < items.length; i++) {
                //通过多选框的checked属性可以获取或设置多选框的选中状态
                // items[i].checked = true;
                items[i].setAttribute('checked',true)
            }
        }
        var user = {}

        function setItem(target,key,value){

        }
        setItem(user,'age',20)   // user=> {age:20}
        setItem(user,'name','zhansan')   // user=> {age:20,name:'zhansan'}
        setItem(user,'age','50')   // user=> {age:50,name:'zhansan'}
        setItem(user,'sb','你是傻逼')   // user=> {age:50,name:'zhansan',sb:'你是傻逼'}


    </script>

</body>

</html>